﻿using System.Collections.Generic;

namespace TfsReports.Web.Models
{
    /// <summary>
    /// Changes
    /// </summary>
    public class Changes : List<Change>
    {
        /// <summary>
        /// Gets or sets the lines added.
        /// </summary>
        /// <value>The lines added.</value>
        public int LinesAdded
        {
            get
            {
                int sum = 0;
                ForEach(c => sum += c.LinesAdded);
                return sum;
            }
        }

        /// <summary>
        /// Gets or sets the lines modified.
        /// </summary>
        /// <value>The lines modified.</value>
        public int LinesModified
        {
            get
            {
                int sum = 0;
                ForEach(c => sum += c.LinesModified);
                return sum;
            }
        }

        /// <summary>
        /// Gets or sets the lines deleted.
        /// </summary>
        /// <value>The lines deleted.</value>
        public int LinesDeleted
        {
            get
            {
                int sum = 0;
                ForEach(c => sum += c.LinesDeleted);
                return sum;
            }
        }

        /// <summary>
        /// Gets the churn.
        /// </summary>
        /// <value>The churn.</value>
        public int Churn { get { return LinesAdded + LinesModified + LinesDeleted; } }

        /// <summary>
        /// Gets the commits.
        /// </summary>
        /// <value>The commits.</value>
        public int Commits
        {
            get
            {
                List<int> changesetIds = new List<int>();
                ForEach(change => { if (!changesetIds.Contains(change.ChangesetId)) changesetIds.Add(change.ChangesetId); });
                return changesetIds.Count;
            }
        }
    }
}
